<?php
class ExamHandler{

    private $regno;
    private $subgr;
	private $month;
	private $marks;
	private $year;
	private $con;
	
	public function setCon($conn){
	
	$this->con=$conn;
	
	}

	public function setRegno($reg){
	
	$this->regno=$reg;
	}

    public function setSubgr($sub){
	
	$this->subgr=$sub;
	}
	
	public function setMonth($mon){
	
	$this->month=$mon;
	}
	public function setYear($yr){
	
	$this->year=$yr;
	}

    public function setMarks($mark){
	
	$this->marks=$mark;
	}
	
	public function setConnect($conn){
	 
	 return $this->con=$conn;
	 }
	
	
//add Student marks to database using this function

//public function marksAdd(){

//$sql1="insert into exam(reg_no,sub_gr,month,marks)      values('$this->regno','$this->subgr','$this->month','$this->marks')";

//$result= mysql_query($sql1,$this->con)or die(mysql_error()); 

//$msg ="Marks Successfully Added";
//return $msg;	

//}




//public function getSubjectProgress($reg,$subgr,$year){

//$sql = "SELECT exam.reg_no, exam.marks, exam.month, subject_code.subject, subject_code.grade
//FROM exam, subject_code, student
//WHERE exam.sub_gr = subject_code.sub_gr
//AND exam.sub_gr = '$subgr'
//AND exam.reg_no = '$reg'
//AND exam.reg_no = student.reg_no
//AND year( student.j_date ) = '$year' ";

//$result=mysql_query($sql,$this->con) or die(mysql_error());
//return $result;
//echo $result;
//}

public function getSubjectProgress($reg,$subgr,$year){

$sql = "SELECT examreg.reg_no, examreg.marks, examdetail.month,examdetail.year, subject_code.subject, subject_code.grade
FROM examdetail,examreg, subject_code, student
WHERE examdetail.sub_gr = subject_code.sub_gr
AND examdetail.sub_gr = '$subgr'
AND examdetail.exam_id = examreg.exam_id
AND examreg.reg_no = '$reg'
AND examreg.reg_no = student.reg_no
AND examdetail.year= '$year'
AND year( student.j_date ) = '$year' 
order by exam_st_id asc";

$result=mysql_query($sql,$this->con) or die(mysql_error());
return $result;
echo $result;
}





public function marksAdd(){
	
	
$result33= mysql_query("Select examreg.marks from examdetail,examreg,student where 
examdetail.month = '$this->month'
AND examdetail.year = '$this->year'
AND examdetail.sub_gr = '$this->subgr'
AND examdetail.exam_id = examreg.exam_id
AND examreg.reg_no = '$this->regno'
AND student.reg_no = examreg.reg_no 
AND year( student.j_date ) = '$this->year' ",$this->con);
$nof=mysql_num_rows($result33); 
if ($nof > 0){
   $msg ="Already entered.";
return $msg;
  }else { 

$result11=mysql_query("select * from examdetail Where month='$this->month' and year='$this->year' and sub_gr='$this->subgr'") or die(mysql_error()) ;
$count=mysql_num_rows($result11);
if($count > 0){
	$result22=mysql_query("select exam_id from examdetail Where month='$this->month' and year='$this->year' and sub_gr='$this->subgr'") or die(mysql_error());
	while($row=mysql_fetch_array($result22)){
	$exam_id=$row['exam_id'];
	}
	$sql1="insert into examreg(exam_id , reg_no , marks )      values($exam_id,'$this->regno','$this->marks')" or die(mysql_error());
	$result= mysql_query($sql1,$this->con)or die(mysql_error()); 
	}
else{
	$sql3="insert into examdetail(month,year,sub_gr)      values('$this->month','$this->year','$this->subgr')" or die(mysql_error());
	$result1=mysql_query($sql3,$this->con) or die(mysql_error());
	$exam_id=mysql_insert_id();
	$sql4="insert into examreg (exam_id,reg_no,marks) values('$exam_id','$this->regno','$this->marks')" or die(mysql_error());
	$result2=mysql_query($sql4,$this->con) or die(mysql_error());
	}
$msg ="Marks Successfully Added.";
return $msg;
///////////////////////////////////
}
}
}
?>
